<?php

	class My_Validate_AllowedEmailDomain extends Zend_Validate_Abstract
	{
	    const EMAIL_DOMAIN_IS_NOT_ALLOWED = 'AllowedEmailDomain';

	    protected $_messageTemplates = array(
	        self::EMAIL_DOMAIN_IS_NOT_ALLOWED => "email domain is not allowed."
	    );

	    public function isValid($value)
	    {

	    	$this->_setValue($value);
	    	
	    	list($emailUserName, $emailDomain) = split("@", $value); 

    		$siteParams = Zend_Registry::get('siteParams');
    		$allowedDomains = $siteParams['signup']['allowedDomains'];
	    		    	
			$validator = new Zend_Validate_InArray(
			    array(
			        'haystack' => $allowedDomains
			    )
			);
		
			if (!$validator->isValid($emailDomain)) {
		            $this->_error(self::EMAIL_DOMAIN_IS_NOT_ALLOWED);
		            return false;
			}
			return true;	    	

	    }

	}
